package au.edu.educationau.opensource.dsm;

import java.beans.Beans;

import au.edu.educationau.opensource.dsm.service.PropertiesService;

public class DSMCoreFactory {
	private static DSMCore instance;

	public static DSMCore getInstance() throws IllegalArgumentException {
		String dsmClassName = PropertiesService.getStringProperty("dsm.core.class", "au.edu.educationau.opensource.dsm.OpenDSMCore");
		return DSMCoreFactory.getInstance(dsmClassName);
	}

	public static synchronized DSMCore getInstance(String classname) throws IllegalArgumentException {
		if (instance != null) {
			return instance;
		} else {
			try {
				DSMCore dsmCore = (DSMCore) Beans.instantiate(Thread.currentThread().getContextClassLoader(), classname);
				dsmCore.init();

				return dsmCore;
			} catch (Exception e) {
				throw new IllegalArgumentException(e);
			}
		}
	}
}
